package com.dk.service.impl;

import com.dk.mapper.TabRouteImgMapper;
import com.dk.mapper.TabRouteMapper;
import com.dk.pojo.TabRoute;
import com.dk.pojo.TabRouteImg;
import com.dk.service.TabRouteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TabRouteServiceImpl implements TabRouteService {

    @Autowired
    private TabRouteMapper tabRouteMapper;
    @Autowired
    private TabRouteImgMapper tabRouteImgMapper;

    @Override
    public List<TabRoute> getInfo(String rname) {
        return tabRouteMapper.select(rname);
    }

    @Override
    public int insert(TabRoute tabRoute) {
        String rimage = tabRoute.getRimage();
        String f = "img//product//small//"+rimage;
        String f1 = "img/product/size4/"+rimage;
        String f2 = "img/product/size2/"+rimage;
        tabRoute.setRimage(f);
        TabRouteImg tri = new TabRouteImg();
        tri.setRid(tabRoute.getRid());
        tri.setBigpic(f1);
        tri.setSmallpic(f2);
        tabRouteImgMapper.insert(tri);
        return tabRouteMapper.insert(tabRoute);
    }

    @Override
    public TabRoute selectById(Integer cid) {
        return tabRouteMapper.selectByPrimaryKey(cid);
    }

    @Override
    public int updateInfo(TabRoute tabRoute) {
        String rimage = tabRoute.getRimage();
        String f = "img//product//small//"+rimage;
        tabRoute.setRimage(f);
        return tabRouteMapper.updateByPrimaryKey(tabRoute);
    }

    @Override
    public int deleteById(Integer rid) {
        return tabRouteMapper.deleteByPrimaryKey(rid);
    }
}
